<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Created by PhpStorm.
 * 
 * User: Administrator
 * Date: 2019/8/26 0026
 * Time: 10:47
 *
 * @property int $id
 * @property string $name
 * @property string $purchase_price
 * @property string $sale_price
 * @property int $category_id
 * @property int $brand_id
 * @property int $create_time
 * @property int $update_time
 * @property float $sort
 * @property int $deleted
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereBrandId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereCategoryId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereCreateTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereDeleted($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product wherePurchasePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereSalePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Product whereUpdateTime($value)
 * @mixin \Eloquent
 * @property-read \App\Models\Brand $brand
 * @property-read \App\Models\Category $category
 */
class Product extends Model
{
    const UPDATED_AT = 'update_time';
    const CREATED_AT = 'create_time';

    protected $dateFormat = 'U';

    public $table = "product";

    protected $guarded = [];

    protected $fillable = ['name', 'purchase_price', 'sale_price', 'category_id', 'brand_id', 'sort', 'deleted'];

    public function brand()
    {
        return $this->belongsTo(Brand::class);
    }

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function getCreateTimeAttribute() {
        return date('Y-m-d H:i:s', $this->attributes['create_time']);
    }

    public function getUpdateTimeAttribute() {
        return date('Y-m-d H:i:s', $this->attributes['update_time']);
    }
}
